//转向新地址
function gotoUrl(url)
{
	url?window.location.href=url:window.location.reload(true);
}
//重新载入验证码
function reloadcaptcha(o)
{
	var d=new Date();
	o.src=o.src.replace(/\d{10,}/,d.getTime());
}
//切换左侧菜单
function toggle_menus()
{
	if($('#wider_pane').css('display') == 'none')
	{
		$('#wider_pane').css('display','');
		$('#wider_footer').css('display','');
		$('#narrow_pane').css('display','none');
		$('#narrow_footer').css('display','none');
		$.get('/?mode=ajmn&type=wider');
	}
	else
	{
		$('#wider_pane').css('display','none');
		$('#wider_footer').css('display','none');
		$('#narrow_pane').css('display','');
		$('#narrow_footer').css('display','');
		$.get('/?mode=ajmn&type=narrow');
	}
}
//
function selectNPD(id, firsttime)
{
	$.get('/?mode=ajnpd&id='+id+'&pid='+$('#pcomputeid').val(),function(d){
		if(d)
		{
			eval("var o="+d);
			if(o.errmsg != '' && firsttime)
			{
				$('#reconfigMsg').html('<span style="color:red;">'+o.errmsg+'</span>');
				$('#confirmReconfigRQ').css('display','none');
			}else
			{
				$('#procnumber').html(o.procnumber);
				$('#cpureserved').html(o.cpureserved);
				$('#cpulimited').html(o.cpulimited);
				$('#ram').html(o.ram);
				$('#ramreserved').html(o.ramreserved);
				$('#ramlimited').html(o.ramlimited);
				$('#iops').html(o.iops);
				if(o.chargemethod != 'free')
				{
					$('#usedmoney').html(o.usedmoney);
					$('#leftmoney').html(o.leftmoney);
					$('#chargerate').html(o.chargerate);
					$('#newmoney').html(o.newmoney);
					$('#reducemoney').html(o.reducemoney);
					$('#diffmoney').html(o.diffmoney);
					
					$('#eusedmoney').html(o.eusedmoney);
					$('#eleftmoney').html(o.eleftmoney);
					$('#enewmoney').html(o.enewmoney);
					$('#ediffmoney').html(o.ediffmoney);
					
					$('#totalmoney').html(o.totalmoney);
				}
			}
		}
	}
	);
}
//checkp
function checkPD()
{	
	var pcid = $('#pcomputeid').val();
	var pctrialcharge = $('#pcompute'+pcid+'-trialrate').val();
	var pcdaycharge = $('#pcompute'+pcid+'-dayrate').val();
	var pcweekcharge = $('#pcompute'+pcid+'-weekrate').val();
	var pcmonthcharge = $('#pcompute'+pcid+'-monthrate').val();
	var pcquartercharge = $('#pcompute'+pcid+'-quarterrate').val();
	var pcyearcharge = $('#pcompute'+pcid+'-yearrate').val();
	var pnid = $('#pnetworkid').val();
	var pntrialcharge = $('#pnetwork'+pnid+'-trialrate').val();
	var pndaycharge = $('#pnetwork'+pnid+'-dayrate').val();
	var pnweekcharge = $('#pnetwork'+pnid+'-weekrate').val();
	var pnmonthcharge = $('#pnetwork'+pnid+'-monthrate').val();
	var pnquartercharge = $('#pnetwork'+pnid+'-quarterrate').val();
	var pnyearcharge = $('#pnetwork'+pnid+'-yearrate').val();	
	if(pctrialcharge != 0 && pntrialcharge !=0){
		$('#time-trial').removeClass('disabled');
		$('#trialtime').removeAttr('disabled');																											
	}else{
		$('#time-trial').addClass('disabled');
		$('#trialtime').attr('disabled','disabled');
  }
	if(pcdaycharge != 0 && pndaycharge !=0){
		$('#time-day').removeClass('disabled');
		$('#daytime').removeAttr('disabled');																											
	}else{
		$('#time-day').addClass('disabled');
		$('#time-day').removeClass('active');
		$('#daytime').attr('disabled','disabled');
  }
	if(pcweekcharge != 0 && pnweekcharge !=0){
		$('#time-week').removeClass('disabled');
		$('#weektime').removeAttr('disabled');																											
	}else{
		$('#time-week').addClass('disabled');
		$('#weektime').attr('disabled','disabled');
  }
}
//产品选择变更信息
function selectPD()
{
	$.get('/?mode=ajpd&id='+$('#p_select').val(),function(d){
		if(d)
		{
			eval("var o="+d);
			$('#prettyname').html(o.prettyname);
			$('#procnumber').html(o.procnumber);
			$('#cpureserved').html(o.cpureserved);
			$('#cpulimited').html(o.cpulimited);
			$('#ram').html(o.ram);
			$('#ramreserved').html(o.ramreserved);
			$('#ramlimited').html(o.ramlimited);
			$('#iops').html(o.iops);
			$('#trialcharge').html(o.ftrialcharge);
			$('#daycharge').html(o.fdaycharge);
			$('#weekcharge').html(o.fweekcharge);
			$('#monthcharge').html(o.fmonthcharge);
			$('#quartercharge').html(o.fquartercharge);
			$('#yearcharge').html(o.fyearcharge);
			
			$('#trialrate').val(o.trialcharge);
			$('#dayrate').val(o.daycharge);
			$('#weekrate').val(o.weekcharge);
			$('#monthrate').val(o.monthcharge);
			$('#quarterrate').val(o.quartercharge);
			$('#yearrate').val(o.yearcharge);
			
			$('#memo').html(o.memo);
			$('#timestamp').html(o.timestamp);
			
			$('#imagename').html(o.imagename);
			$('#osname').html(o.osname);
			$('#disksize').html(o.disksize);
			$('#reloadtime').html(o.reloadtime);
			$('#software').html(o.software);
			$('#intro').html(o.intro);
			$('#osimagename').attr('src',o.osimagename);
			
			if(o.ftrialcharge == '-')
			{
				$('#trial').css('display','none');
				$('#trialcon').css('display','none');
			}else
			{
				$('#trial').css('display','');
				$('#trialcon').css('display','');
			}	
			if(o.fweekcharge == '-')
			{
				$('#week').css('display','none');
				$('#weekcon').css('display','none');
			}else
			{
				$('#week').css('display','');
				$('#weekcon').css('display','');
			}			
			if(o.fmonthcharge == '-')
			{
				$('#month').css('display','none');
				$('#monthcon').css('display','none');
			}else
			{
				$('#month').css('display','');
				$('#monthcon').css('display','');
			}			
			if(o.fquartercharge == '-')
			{
				$('#quarter').css('display','none');
				$('#quartercon').css('display','none');
			}else
			{
				$('#quarter').css('display','');
				$('#quartercon').css('display','');
			}			
			if(o.fyearcharge == '-')
			{
				$('#year').css('display','none');
				$('#yearcon').css('display','none');
			}else
			{
				$('#year').css('display','');
				$('#yearcon').css('display','');
			}
			calcharge();
		}
	}
	);
}
function calcharge()
{
		var chargetype = $("input[name=chargetype]").val();
		var chargerate = 0;
		var totalcharge = 0;
		chargerate = parseFloat(parseInt($('#pcompute-'+chargetype+'rate').val()) + parseInt($('#pnetwork-'+chargetype+'rate').val()));
		//alert(chargerate);
		if(chargetype == 'trial')
		{
			$('#totalcharge').html(parseInt($('#'+chargetype+'time').val()) * chargerate + '个试用许可');
		}else
		{
			$('#totalcharge').html(parseFloat(parseInt($('#'+chargetype+'time').val()) * chargerate).toFixed(2) + '元');
		}
}
//bulk CalCharge
function bulkCalCharge()
{
		var rq = new Array();
		var chargetype = $("input[name=chargetype]").val();
		var totalchargerate = 0;
						
 		$("input[name='chkSon']:checkbox:checked").each(function(){
     		rq.push($(this).val());
 		});
 		if(rq.length > 10) {
 				alert('您最多可以同时选择10台机器！');
 		}else{
 			for(i=0;i<rq.length;i++) {
 				$.get('/?mode=ajpp&id='+rq[i]+'&chargetype='+chargetype,function(d){
				if(d)
				{
					totalchargerate = totalchargerate + Number(d);
 					$('#totalcharge').html(parseFloat(parseInt($('#'+chargetype+'time').val()) * totalchargerate).toFixed(2) + ' 元');
 					if((parseInt($('#'+chargetype+'time').val()) * totalchargerate) > parseInt($('#totalmoney').val())) {
	 					$('#moneytip').css('display','');
	 					$('#bulkExtendRQ').attr('disabled','disabled');
	 				}else{
	 					$('#moneytip').css('display','none');
	 					$('#bulkExtendRQ').removeAttr('disabled','');
	 				}
 				}	
 			});
 		} 		
	}
}
//bulk extendRQ
function bulkExtendRQ()
{
		var rq = new Array();		
		var chargetype = $("input[name=chargetype]").val();
		var chargetime = $('#'+chargetype+'time').val();		
 		$("input[name='chkSon']:checkbox:checked").each(function(){
     		rq.push($(this).val());
 		});
 		if(rq.length > 10) {
 				alert('您最多可以同时选择10台机器！');
 		}else{
 			for(i=0;i<rq.length;i++) {
				//extendRQ(rq[i]);
				
			//$.post("/?mode=ajet",{"id":rq[i], "type":chargetype, "time":chargetime},function(d){
/*
			$.get('/?mode=ajet&id='+rq[i]+'&type='+chargetype+'&time='+chargetime,function(d){
				if(d=="PASS")
				{
					//alert('成功将该资源的使用时间延长');
					//gotoUrl();
				}else
				{
					alert(d);
				}
			});
*/			
			$.ajax({
								type: "GET",
								url: "/?mode=ajet",
								dataType: 'html',
								data: {
												id: rq[i],
												type: chargetype,
												time: chargetime
								},
								async:false,	//fix firefox bug
								success: function (d) {
									// do something!
									if(d=="PASS")
									{
										//alert('成功将该资源的使用时间延长');
										//gotoUrl();
									}else
									{
										alert(d);
									}
								},
								error: function (xhr, textStatus, errorThrown) {
									alert('error ' + (errorThrown ? errorThrown : xhr.status));
								}
						});					
 			}
 			gotoUrl();	
 		} 		
}
//选择组成员
function selectGM(rquid,obj,objid,gmid)
{
	$.get('/?mode=ajgm&id='+obj.value+"&uid="+rquid+'&objid='+gmid,function(d){
		if(d)
		{
			$('#'+objid).html(d);
		}
	}
	);
}

function mapwanPort(id, oid, act)
{
	var localport = 0;
	if(act == 'add')
	{
		localport = $('#localport'+oid).val();
		if(isNaN(localport) || localport == 0 || localport > 65535)
		{
			alert('请正确输入需要映射的本地端口号');
			return false;
		}else if(localport == 22 || (localport >= 5900 && localport <= 6000) || localport == 3389 || localport == 25 || localport == 110)
		{
			alert('本地端口22，25，110，3389，5900-6000为保留端口，不能进行外网映射');
			return false;
		}
	}
	$.get('/?mode=ajmp&id='+id+'&oid='+oid+'&port='+localport+'&act='+act, function(d){
		if(d == "PASS")
		{
			alert('操作成功');
			gotoUrl();
		}else
		{
			alert(d);
		}
	})
}
//选择存储所映射到的主机
function selectVSH()
{
	$.get('/?mode=ajvsh&id='+$('#vmstorageid').val(),function(d){
		if(d)
		{
			$('#vmhosts').html(d);
		}
	}
	);
}
function reloadVHRQ(vhid)
{
	if(confirm("进行迁移前请确保该主机上所有资源已经处于关闭状态，确认进行迁移操作吗？"))
	{
		$.get('/?mode=ajvhrd&id='+vhid,function(d){
			if(d=="PASS")
			{
				alert('迁移任务添加成功，该段时间请不要对资源进行其他操作');
				gotoUrl();
			}else
			{
				alert(d);
			}
		}
		)
	}
}
function powerVMS(id,scope,action,powertype)
{
	if(confirm("请再次确认你的操作？"))
	{
		$.get('/?mode=ajpvms&id='+id+'&scope='+scope+'&action='+action+'&powertype='+powertype,function(d){
			if(d=="PASS")
			{
				alert('任务已提交');
				gotoUrl();
			}else
			{
				alert(d);
			}
		}
		)
	}
}
/*
function powerMNVH(mnid)
{
	if(confirm("进行迁移前请确保该主机上所有资源已经处于关闭状态，确认进行迁移操作吗？"))
	{
		$.get('/?mode=rd&id='+mnid,function(d){
			if(d=="PASS")
			{
				alert('迁移任务添加成功，该段时间请不要对资源进行其他操作');
				gotoUrl();
			}else
			{
				alert(d);
			}
		}
		)
	}
}*/
//
function checkMSG(id,type)
{
	//if(confirm("不要再提醒？"))
	//{
		$.get('/?mode=ajchk&id='+id+'&type='+type,function(d){
			if(d=="PASS")
			{
				document.getElementById('attention').style.display = "none";			
			}else
			{
				alert(d);
			}
		}
		)
	//}
}
function reloadRQ(rqid)
{
	if(confirm("进行迁移前请确保该资源已经处于关闭状态，确认进行迁移操作吗？"))
	{
		$.get('/?mode=ajrd&id='+rqid,function(d){
			if(d=="PASS")
			{
				alert('迁移任务添加成功，该段时间请不要对资源进行其他操作');
				gotoUrl();
			}else
			{
				alert(d);
			}
		}
		)
	}
}
function reloadRRQ(rqid)
{
	if(confirm("确认重新进行迁移操作吗？"))
	{
		$.get('/?mode=ajrrd&id='+rqid,function(d){
			if(d=="PASS")
			{
				alert('迁移任务添加成功');
				gotoUrl();
			}else
			{
				alert(d);
			}
		}
		)
	}
}
////删除申请资源
//function deleteRQ(rqid)
//{
//	if(rqid)
//	{
//		if(confirm("确认要删除该资源？"))
//		{
//			$.get('/?mode=ajdl&id='+rqid,function(d){
//				if(d=="PASS")
//				{
//					alert('资源删除成功');
//					gotoUrl('/?mode=jobs&type=pending');
//				}else
//				{
//					alert(d);
//				}
//			}
//			)
//		}
//	}
//
//}
//连接申请资源
function connectRQ(rqid)
{
	if(rqid)
	{
		gotoUrl('/?mode=requesting&id='+rqid+'&console');
	}
}
//释放申请资源
function releaseRQ(rqid)
{
	if(rqid)
	{
		$.get('/?mode=ajrl&id='+rqid,function(d){
			if(d=="PASS")
			{
					gotoUrl('/?mode=jobs');
			}else
			{
					alert(d);
			}
		}
		)
	}
}
//延长申请资源使用时间
function extendRQ(rqid)
{
	if(rqid)
	{
			var chargetype = $("input[name=chargetype]").val();
			var chargetime = $('#'+chargetype+'time').val();
			//$.post("/?mode=ajet",{'id':rqid, 'type':chargetype, 'time':chargetime},function(d){
			$.get('/?mode=ajet&id='+rqid+'&type='+chargetype+'&time='+chargetime,function(d){
				if(d=="PASS")
				{
					//alert('成功将该资源的使用时间延长');
					//gotoUrl();
				}else
				{
					alert(d);
				}
			});
	}
}
//统一补偿维护时间
function payRQ(id,scope,days)
{
	if(id && scope && days)
	{
		if(confirm("确认给于补偿？"))
		{
			$.get('/?mode=ajpay&id='+id+'&scope='+scope+'&days='+days,function(d){
				if(d=="PASS")
				{
					alert('成功补偿'+days+'天');
					gotoUrl();
				}else
				{
					alert(d);
				}
			}
			)
		}
	}
}
function reconfigRQ(rqid)
{
	$.get('/?mode=ajrf&id='+rqid+'&pid='+$('#pcomputeid').val(),function(d){
		if(d=='PASS')
		{
			alert('成功发出对该资源进行重新配置的请求！');
			gotoUrl();
		}else
		{
			alert(d);
		}
	});
}
//资源控制权转移
function transRQ(rqid,objid)
{
	if(rqid)
	{
		var uid = $('#'+objid).val();
		if(uid != undefined)
		{
			if(confirm("确认将该资源的控制权转移吗？转移后你将不能继续使用该资源！"))
			{
				$.get('/?mode=ajts&id='+rqid+'&uid='+uid,function(d){
					if(d == "PASS")
					{
						alert('成功将该资源的控制权转移！');
						gotoUrl('/?mode=jobs');
					}else
					{
						alert(d);
					}
				}
				)
			}
		}
	}
}
//申请资源进程
function processRQ(rqid)
{
	if(rqid)
	{
		$.get('/?mode=ajpc&id='+rqid,function(d)
		{
			if(d)
			{
				eval("var o="+d);
				//if(o.st_image == 'st_active')
				//{
				//	gotoUrl();
				//}else
				//{
					$('#role-0-loading-detail1').html(o.loadhtml);
					$('#role-0-loading-detail2').html(o.loadhtml);
					$('#role-0-loading-detail').html(o.loadhtml);
					$('.role-0-loading-image').attr('src','/themes/e2cloud/images/'+o.st_image+'.gif');
					$('.role-0-loading-image').attr('title',o.st_title);
					$('#role-0-loading-time').html(o.st_time);
					if(o.st_image == 'st_active')
					{
						window.clearTimeout(procInterval);
						$('#st_image').attr('src','/themes/e2cloud/images/'+o.st_image+'.gif');
						$('#st_image').attr('title',o.st_title);
						$('#st_title').html(o.st_title);
						$('#st_extra').html("<input type=\"button\" value=\"连接\" onclick=\"javascript:connectRQ("+rqid+")\" />\n<input type=\"button\" value=\"结束\" onclick=\"javascript:releaseRQ("+rqid+")\" />");
						$('.vmipaddr').html(o.vmipaddr);
						$('#lastcheckin').html(o.lastcheckin);
						$('#pw').html(o.pw);
					}else if(o.st_image == 'st_failed')
					{
						window.clearTimeout(procInterval);
						$('#st_image').attr('src','/themes/e2cloud/images/'+o.st_image+'.gif');
						$('#st_image').attr('title','预定失败');
						$('#st_title').html('预定失败');
						$('#st_extra').html("");
					}else
					{
						procInterval = window.setTimeout('processRQ('+rqid+')',5000);
					}
				//}
			}
		}
		)
	}
}

//申请创建应用模板进程
function processImageRQ(ivid,dmode)
{
	if(ivid)
	{
		$.get('/?mode=ajipc&type='+dmode+'&id='+ivid,function(d)
		{
			if(d)
			{
				eval("var o="+d);
				if(o.st_image == 'st_active')
				{
					gotoUrl();
				}else
				{
					$('#role-0-loading-detail2').html(o.loadhtml);
					$('#role-0-loading-detail').html(o.loadhtml);
					$('.role-0-loading-image').attr('src','/themes/e2cloud/images/'+o.st_image+'.gif');
					$('.role-0-loading-image').attr('title',o.st_title);
					if(o.st_image == 'st_failed')
					{
						window.clearTimeout(procInterval);
						$('#st_image').attr('src','/themes/e2cloud/images/'+o.st_image+'.gif');
						$('#st_image').attr('title','失败');
						$('#st_title').html('失败');
					}else
					{
						procInterval = window.setTimeout('processImageRQ(\''+ivid+'\',\''+dmode+'\')',5000);
					}
				}
			}
		}
		)
	}
}
//部署应用模板进程
function processImageDP(ivid,type)
{
	if(ivid)
	{
		var msg = '';	
		if(type == 'basedeploy')
		{
			msg = "确认要重新部署该基础模板吗？";
		}else if(type == 'deploy')
		{
			msg = "确认要重新申请该应用模板吗？";
		}else
		{
			msg = "确认要部署该模板么？部署期间请不要对模板进行任何操作！";
		}
		if(confirm(msg))
		{
			$.get('/?mode=ajidp&id='+ivid+'&type='+type,function(d){
				if(d == "PASS")
				{
					gotoUrl();
				}else
				{
					alert(d);
				}	
			})
		}
	}	
}
//部署应用模板到存储
function deployAP(id, vsid, r)
{
	if(id)
	{
		if(vsid == 'vmstorageid1')
		{
			if(!confirm("确认要重新部署该模板到指定存储吗？"))
			{
				return false;	
			}
		}
		var vmstorageid = $('#'+vsid).val();
		$.get('/?mode=ajidt&id='+id+'&vmstorageid='+vmstorageid+'&act='+r,function(d){
			if(d == "PASS")
			{
				alert('提交成功，系统稍后为您部署模板到指定的存储！');
				//gotoUrl();
			}else
			{
				alert(d);
			}
		})
	}
}
//部署模板
function deployRC(id)
{
	if(id)
	{
		var vsid= $('#vsid').val();
		var cnt = $('#dcnt').val();
		if(cnt.length == 0 || cnt == 0)
		{
			alert('请输入要部署的个数');
		}else
		{
			$.get('/?mode=ajidr&id='+id+'&vsid='+vsid+'&cnt='+cnt,function(d){
				if(d == "PASS")
				{
					alert('提交成功，系统将在预置的部署时间内开始部署这些资源！');
					$('#irdeploycon').css('display','none');
					$('#dcnt').val('');
				}else
				{
					alert(d);
				}
			})
		}
	}
}
function checkdeployRC(id, vsid)
{
		$('#checkdeploy'+vsid).html('<div class="col-md-6"><div class="input-group"><span class="input-group-btn"><input id="vsid" type="hidden" value=\''+vsid+'\' /><input id="dcnt" type="text" size="6" value="" class="form-control" /><button onclick="javascript:deployRC(\''+id+'\');" class="btn btn-primary">部署</button></span></div></div>');
}
//创建快照
function createSnapshot(rqid,o)
{
    if(rqid)
    {
        var intro = $('#role-0-snapshot-create-intro').val();
        if(intro == "")
        {
            alert("请输入该快照的描述信息");
        }else
        {
            o.disabled=true;
            $.get('/?mode=spcss&id='+rqid+'&intro='+encodeURI(intro),function(d){
                if(d == "PASS")
                {
                    alert('快照创建成功');
                    gotoUrl('/?mode=requesting&id='+rqid+'&console');
                }else
                {
                    alert(d);
                    o.disabled=false;
                } 
            })
        }
    }
}
function revertSnapshot(rqid,ssid)
{
    if(rqid && ssid)
    {
    	  document.getElementById('snapshottip').innerHTML = "正在将您选择的机器恢复到初始系统，恢复时间大约需要30秒，请耐心等待，不要关闭本窗口...";
    	  $('#confirmRevertSnapshot').attr('disabled','disabled');
    	  $('#confirmRevertSnapshot').html('正在处理');	    	  	
        $.get('/?mode=spvss&id='+rqid+'&sid='+ssid,function(d){
            if(d == "PASS")
            {
                //alert('恢复快照成功，如果机器没有正常开机，请手动点 开机');
                document.getElementById('snapshottip').innerHTML = '<span class="glyphicon glyphicon-ok"></span> 快照已经恢复成功，如果机器没有正常开机，请手动点 开机';
    	  				$('#confirmRevertSnapshot').css('display','none');
    	  				$('#cancelRevertSnapshot').html('确定');	    	  	
                //gotoUrl();
            }else
            {
                alert(d);
            }   
        })
    }
}
function removeSnapshot(rqid,ssid)
{
    if(rqid && ssid)
    {
    	if(confirm('请将当前快照转到此快照及其子快照以外的快照上，确认要删除这个快照及其所有子快照吗？'))
    	{
        $.get('/?mode=sprss&id='+rqid+'&sid='+ssid,function(d){
            if(d == "PASS")
            {
                alert('快照删除成功');
                gotoUrl('/?mode=requesting&id='+rqid+'&console');
            }else
            {
                alert(d);
            }   
        })
      }
    }
}
//模板电源操作
function powerST(id,power,type)
{
	if(id != '')
	{
		$.get('/?mode=sppow&id='+id+'&power='+power+'&type='+type,function(d){
			if(d == "PASS")
			{
				alert('操作成功');
				$('#consolerefresh').click();
			}else
			{
				alert(d);
			}
		})
	}else
	{
		var arrSon = document.getElementsByName('chkSon');
		var checkCount = 0;
		for(var i=0; i<arrSon.length; i++) {
     		if(arrSon[i].checked){
     			checkCount ++;
     		}
 		}
  	if(checkCount > 10) {
  		alert('您最多可以同时选择10台机器！');
  	}else{
  		if(power == 'stop') var action = '关闭';  		
  		if(power == 'start') var action = '启动';
  		if(power == 'reset') var action = '强制重启';
  		
  		if(checkCount > 1){
  				if(confirm('您确定要同时'+action+'这 '+checkCount+'台机器吗？')){
 					$("input[name='chkSon']:checkbox:checked").each(function(){
     				var id = $(this).val();
     				$.get('/?mode=sppow&id='+id+'&power='+power+'&type='+type)
 					});
 					alert('操作成功');
 				}
 			}else{
 				if(confirm('您确定要'+action+'这台机器吗？')){
 				$("input[name='chkSon']:checkbox:checked").each(function(){
     			var id = $(this).val();
     			$.get('/?mode=sppow&id='+id+'&power='+power+'&type='+type)
 				});
 				alert('操作成功');
 			}
 			}
 		}		
 	} 			 			
}
//切换模板镜像
function switchISO(id,flag,type)
{
	var isoid = $('#isoid').val();
	if(flag == 0) isoid = 0;
	if(id)
	{
		$.get('/?mode=spmnt&id='+id+'&isoid='+isoid+'&type='+type,function(d){
			if(d == "PASS")
			{
				alert('操作成功');
			}else
			{
				alert(d);
			}
		})
	}
}
function changePORT(id)
{
	if(id)
	{
		if(confirm('确认要更改该资源的访问端口？'))
		{
			$.get('/?mode=ajcp&id='+id,function(d){
				{
					if(d == "PASS")
					{
						alert('操作成功');
						gotoUrl();
					}else
					{
						alert(d);
					}
				}
			})
		}
	}
}
//扫描存储目录镜像文件
function scanISO()
{
	var storageid=$('#storageid').val();
	if(storageid)
	{
		$('#isolist table tr.rowOnBlue').remove();
		$('#isolist table tr.noitems').remove();
		$('#loading').css('display','');
		$.get('/?mode=spsc&id='+storageid,function(d){
			if(d)
			{
				$('#isolist').html(d);
			}	
		})
	}
}
//操作镜像文件
function operateISO(id,flag)
{
	if(id && flag)
	{
		var intro = $('#intro'+id).val();
		if(flag == 'remove')
		{
			if(!confirm('确实要移除该文件么？'))
			{
				return false;
			}
		}
		if(flag == 'update')
		{
			if(!confirm('确定要修改该详细介绍吗？')) return false;
			
		}
		$.get('/?mode=ajiso&id='+id+'&flag='+flag+'&intro='+encodeURIComponent(intro),function(d){
				if(d == "PASS")
				{
					alert("操作成功");
					if(flag == 'add')
					{
						$('#s'+id).html('<span style="color:blue">已添加</span>');
						$('#b'+id).html('<input type="button" value="移除" onclick="javascript:operateISO(\''+id+'\',\'remove\');" />');
						$('#i'+id).append('<input type="button" value="更新" onclick="javascript:operateISO(\''+id+'\',\'update\');" />');
					}else if(flag == 'remove')
					{
						$('#i'+id+' :last').remove();
						$('#s'+id).html('未添加');
						$('#b'+id).html('<input type="button" value="添加" onclick="javascript:operateISO(\''+id+'\',\'add\');" />');
					}
				}else
				{
					alert(d);
				}
		})
	}
}
function setPrivateISO(userid, isoid, action)
{
	$.get('/?mode=ajax_private_iso&userid='+userid+'&isoid='+isoid+'&action='+action,function(result){
		alert(result);
		if(result === "操作完成" && action === "del")
		{
			window.location="/?mode=isos&type=private";
		}
	});
}
//切换控制台
function switchConsole(id,type)
{
	var t = $('#consoletype').val();
	if(t == 'CONSOLE')
	{
		$('#role-0-console-iframe').attr('src','/?mode=console&type='+type+'&id='+id+'&frameid=role-0-console-iframe');
	}else if(t == 'HOSTVNC')
	{
		$('#role-0-console-iframe').attr('src','/?mode=hostvnc&type='+type+'&id='+id+'&frameid=role-0-console-iframe');
	}else if(t == 'HOSTVNCINFO')
	{
		$('#role-0-console-iframe').attr('src','/?mode=hostvncinfo&type='+type+'&id='+id);
	}else if(t == 'RDP')
	{
		$('#role-0-console-iframe').attr('src','/?mode=rdp&type='+type+'&id='+id+'&frameid=role-0-console-iframe');
	}else if(t == 'RDPINFO')
	{
		$('#role-0-console-iframe').attr('src','/?mode=rdpinfo&type='+type+'&id='+id);
	}else if(t == 'VNC')
	{
		$('#role-0-console-iframe').attr('src','/?mode=vnc&type='+type+'&id='+id+'&frameid=role-0-console-iframe');
	}else if(t == 'VNCINFO')
	{
		$('#role-0-console-iframe').attr('src','/?mode=vncinfo&type='+type+'&id='+id);
	}else if(t == 'SSH')
	{
		$('#role-0-console-iframe').attr('src','/?mode=ssh&type='+type+'&id='+id);
	}
}

//发表建议
function sendAdv()
{
	var adv = $('#adv').val();
	if(adv == '我也提点建议，20字符以' || adv == '' || adv.length == 0)
	{
		alert('请输入建议内容');
	}else
	{
		if(adv.length > 20)
		{
			alert('对不起，建议不能超过20个字符');
		}else
		{
			$.post("/?mode=ajad",{'adv':adv},function(d){
				if(d=="PASS")
				{
					alert("建议发表成功");
					gotoUrl();
					//$('#adv').val('快速发表建议，20字符以内');
				}else
				{
					alert(d);
				}
			})
		}
	}
}
//用户状态操作
function opuser(userid, flag)
{
	if(flag == 0 || flag == 1)
	{
		if(confirm('确定要'+(flag==1?'启用':'禁用')+'该用户吗？'))
		{
			$.get('/?mode=ajou&id='+userid+'&flag='+flag,function(d){
				if(d=="PASS")
				{
					alert('操作成功');
					gotoUrl();
				}else
				{
					alert(d);
				}
			});
		}
	}else if(flag == 2 || flag == 3)
	{
		if(confirm('确定要'+(flag==3?'手动激活':'重新激活')+'该用户邮箱账号吗？'))
		{
			$.get('/?mode=ajou&id='+userid+'&flag='+flag,function(d){
				if(d=="PASS")
				{
					alert('操作成功');
					gotoUrl();
				}else
				{
					alert(d);
				}
			});
		}	
	}
}
function deluser(userid, flag)
{
	if(userid)
	{
		if(confirm("确认要删除该用户？"))
		{
			$.get('/?mode=ajdu&id='+userid+'&flag='+flag,function(d){
				if(d=="PASS")
				{
					alert('用户删除成功');
					gotoUrl('/?mode=users');
				}else
				{
					alert(d);
				}
			}
			)
		}
	}

}
//模板状态操作
function opimage(imageid, flag)
{
	if(confirm('确定要'+(flag==1?'启用':'禁用')+'该模板吗？'))
	{
		$.get('/?mode=ajoi&id='+imageid+'&flag='+flag,function(d){
			if(d=="PASS")
			{
				alert('操作成功');
				gotoUrl();
			}else
			{
				alert(d);
			}
		});
	}
}
function delimage(imageid)
{
	if(confirm('确定要删除该模板吗？提交后，它所有的关联模版都将会被删除!!!'))
	{
		$.get('/?mode=ajdi&id='+imageid,function(d) {
			if(d=="PASS")
			{
				alert('操作成功');
				gotoUrl('/?mode=images');
			}else
			{
				alert(d);
			}
		});
	}
}
//产品状态操作
function opproduct(id, flag)
{
	if(confirm('确定要'+(flag==1?'启用':'禁用')+'该产品吗？'))
	{
		$.get('/?mode=ajop&id='+id+'&flag='+flag,function(d){
			if(d=="PASS")
			{
				alert('操作成功');
				gotoUrl();
			}else
			{
				alert(d);
			}
		});
	}
}
function delproduct(id)
{
	if(confirm('确定要删除该产品吗？'))
	{
		$.get('/?mode=ajdp&id='+id,function(d) {
			if(d=="PASS")
			{
				alert('操作成功');
				gotoUrl('/?mode=products');
			}else
			{
				alert(d);
			}
		});
	}
}
//主机状态操作
function ophost(hostid, flag)
{
    var msg;
    if(flag == 1)
    {
        msg = "确定要启用该主机吗？";
    }else
    {
        msg = "确定要禁用该主机吗？禁用之后一些已经在该主机上的申请将无法得到响应！";
    }
	if(confirm(msg))
	{
		$.get('/?mode=ajoh&id='+hostid+'&flag='+flag,function(d){
			if(d=="PASS")
			{
				alert('操作成功');
				gotoUrl();
			}else
			{
				alert(d);
			}
		});
	}
}
//公共信息删除
function delmsg(msgid)
{
	if(confirm('确定要删除该信息吗？删除之后不可恢复！'))
	{
		$.get('/?mode=ajdm&id='+msgid,function(d){
			if(d=="PASS")
			{
				alert('操作成功');
				gotoUrl('/?mode=messages');
			}else
			{
				alert(d);
			}
		});
	}
}
//支持信息删除
function delfaq(faqid)
{
	if(confirm('确定要删除该信息吗？删除之后不可恢复！'))
	{
		$.get('/?mode=ajds&id='+faqid,function(d){
			if(d=="PASS")
			{
				alert('操作成功');
				gotoUrl('/?mode=supports');
			}else
			{
				alert(d);
			}
		});
	}
}

function userdisk(id)
{
	var sz=$('#disksize').val();
	if(confirm('添加磁盘时候，系统将会重启，请确认已将数据保存完毕！确定要添加磁盘么！'))
	{
		if(isNaN(sz) || sz <= 0)
		{
			alert('对不起，磁盘大小不正确！');
		}else
		{
			$.get('/?mode=spud&id='+id+'&sid='+$('#vmstorageid').val()+'&size='+sz,function(d){
				if(d=="PASS")
				{
					alert('磁盘添加成功，请稍候');
					gotoUrl();
				}else
				{
					alert(d);
				}
			});
		}
	}
}
//
function Ipinfo(ip,info,action)
{
	//alert('1');
	if(action != 'preferisp'){
		//alert('1');
		var sz = document.getElementById(ip).innerHTML;
		if(sz == ip){
		$.get('/?mode=ajipinfo&ip='+ip+'&info='+info,function(d){
			if(d)
			{
				document.getElementById(ip).innerHTML=d;
			}
		}	
		);
		}else{
				document.getElementById(ip).innerHTML=ip;
		}
	}else{
		//alert('2');
		$.get('/?mode=ajipinfo&ip='+ip+'&info='+info+'&action='+action);
	}
}
//
function deldisk(id)
{
	if(confirm('删除磁盘时候，系统将会重启，请确认已将数据保存完毕！确定要删除该磁盘么？删除之后磁盘数据将被清空！'))
	{
		$.get('/?mode=spdd&id='+id,function(d){
			if(d=="PASS")
			{
				alert('操作成功');
				gotoUrl();
			}else
			{
				alert(d);
			}
		});
	}
}
// --列头全选框被单击---
function ChkAllClick(sonName, cbAllId){
    var arrSon = document.getElementsByName(sonName);
 		var cbAll = document.getElementById(cbAllId);
 		var tempState=cbAll.checked;
 		for(i=0;i<arrSon.length;i++){
  			if(arrSon[i].checked != tempState)
           arrSon[i].click();
 		}
}

// --子项复选框被单击---
function ChkSonClick(sonName, cbAllId){
 		var arrSon = document.getElementsByName(sonName);
		var cbAll = document.getElementById(cbAllId);
 		for(var i=0; i<arrSon.length; i++) {
     		if(!arrSon[i].checked){
     		cbAll.checked = false;
     		return;
     		}
 		}
 		cbAll.checked = true;
}

// --反选被单击---
function ChkOppClick(sonName){
		 var arrSon = document.getElementsByName(sonName);
 		 for(i=0;i<arrSon.length;i++){
  			arrSon[i].click();
 			}
}
function chkBox(id){
	var requestBox = document.getElementById('requestBox-'+id);
 	var tempState=requestBox.checked;
 	if(tempState){
		requestBox.checked = false;
	}else{
		requestBox.checked = true;
	}
}
// 
function CheckRequestTools(sonName){
		 var arrSon = document.getElementsByName(sonName);
		 var checkCount = 0;
 		 for(var i=0; i<arrSon.length; i++) {
     		if(arrSon[i].checked){
     			checkCount++;
     		}
 		}
 		if(checkCount <= 10 && checkCount > 0){
 			$('#PowerOff').removeAttr('disabled'); 			
 			$('#PowerOn').removeAttr('disabled');
 			$('#PowerReset').removeAttr('disabled');
 			$('#ExtendRQ').removeAttr('disabled');
 			$('#MoreTools').removeAttr('disabled'); 			
 		}else{
 			$('#PowerOff').attr('disabled','disabled');	
 			$('#PowerOn').attr('disabled','disabled');
 			$('#PowerReset').attr('disabled','disabled');
 			$('#ExtendRQ').attr('disabled','disabled');
 			$('#MoreTools').attr('disabled','disabled');
 		}
 		if(checkCount < 2 && checkCount > 0){
 			$('#RestoreOS').removeAttr('disabled');			  		    	
 			$('#ReconfigRQ').removeClass('disabled');
 			$('#ReleaseRQ').removeClass('disabled');
 			$('#MapwanPort').removeClass('disabled');
 			$('#UserDisk').removeClass('disabled');				 				 			 							 				 			 							 				 			 							 				 			
     	var id = $("input[name='chkSon']:checkbox:checked").val();
     	$('#RestoreOS').attr('href','/?mode=snapshot&id='+id);
     	$('a#ReleaseRQ').attr('href','/?mode=releaserq&id='+id);
     	$('a#ReconfigRQ').attr('href','/?mode=reconfigrq&id='+id);
     	$('a#MapwanPort').attr('href','/?mode=mapwanport&id='+id);
     	$('a#UserDisk').attr('href','/?mode=userdisk&id='+id);     	     	     	     	     	     	     	
 		}else{
 			$('#RestoreOS').attr('disabled','disabled');
  		$('#RestoreOS').attr('href','#');
 			$('#ReconfigRQ').addClass('disabled','disabled');
 			$('#ReleaseRQ').addClass('disabled','disabled');
 			$('#MapwanPort').addClass('disabled','disabled');
 			$('#UserDisk').addClass('disabled','disabled'); 			 			 			
 			$('a#ReleaseRQ').attr('href','#');
 			$('a#ReconfigRQ').attr('href','#');
 			$('a#MapwanPort').attr('href','#'); 
 			$('a#UserDisk').attr('href','#'); 			 			 			 			 			 			 			 						 			 			 			 			 			 			
 		}
}
function editRequestName(id)
{
	var RequestName = document.getElementById('editRequestName-'+id);
 	var tempState=RequestName.style.display;
 	if(tempState == ''){
		$('#editRequestName-'+id).css('display','none');
		$('#submitRequestName-'+id).css('display','');
	}else{
		$('#editRequestName-'+id).css('display','');
		$('#submitRequestName-'+id).css('display','none');
	}
}
function submitRequestName(id,jobname)
{
	var tempName = $('#requestName-'+id).val();
	if(tempName != jobname)
	{
		$.post('/?mode=ajrqrename', {requestid:id, requestname:tempName}, function(d){
			if(d=="PASS")
			{
				gotoUrl();
			}else
			{
				alert(d);
			}
		});
	}else{
		$('#editRequestName-'+id).css('display','');
		$('#submitRequestName-'+id).css('display','none');
	}
}
//
function showRequestTools(id)
{
  	$("#editRequestflag-"+id).css('display','');
  	$("#editRequestTixing-"+id).css('display','');	       	     
}
function hideRequestTools(id)
{	
  	$("#editRequestflag-"+id).css('display','none');
  	$("#editRequestTixing-"+id).css('display','none');  	      	       	
}
function addTixing(id)
{	
  	var endtime = $('#endtime-'+id).html();
		var __qqClockShare = {
  	 	content: "guajibao.me 提醒您有机器到期，请提前续费哦！",
  	 	time: endtime,
   		advance: 0,
   		url: "http://guajibao.me",
   		icon: "1_1"
		};	
		window.open('http://qzs.qq.com/snsapp/app/bee/widget/open.htm#content=' + encodeURIComponent(__qqClockShare.content) +'&time=' + encodeURIComponent(__qqClockShare.time) +'&advance=' + __qqClockShare.advance +'&url=' + encodeURIComponent(__qqClockShare.url) + '');
}
function requestTip()
{	
  	var pcomputeid = $('#pcomputeid').val();
  	var imagerevisionid = $('#imagerevisionid').val();
  	var pnetworkid = $('#pnetworkid').val();
  	
  	if(pcomputeid == '')
  	{
  		$('#pcompute-div').css('border','2px #0095bb solid');
  		//$("#request-tip").html("请选择机器配置!");
  	}else if(imagerevisionid == "")
  	{
  		$('#pimagerevision-div').css('border','2px #0095bb solid');
  		//$("#request-tip").html("请选择系统模板!");
  	}else if(pnetworkid == "")
  	{
  		$('#pnetwork-div').css('border','2px #0095bb solid');
  		//$("#request-tip").html("请选择网络类型!");
  	}
  	if(pcomputeid != '')
  	{
  		$('#pcompute-div').css('border','');
  	}
  	if(imagerevisionid != '')
  	{
  		$('#pimagerevision-div').css('border','');
  	}
  	if(pnetworkid != '')
  	{
  		$('#pnetwork-div').css('border','');
  	}
  	
/*  	if(pcomputeid != '' && imagerevisionid != '' && pnetworkid != '')
  	{
  		$('#request-tip-div').css('display','none');
  	}*/
}
//初始化控件特效
/*$(document).ready(function()
{
	$("input").each(function(i){
		if(this.type=='text' || this.type=='file' || this.type=='password')
		{
			this.style.border="1px solid #7F9DB9";
			this.style.margin="1px";
			this.onfocus=function(){
				this.style.border="2px solid #9EC9F6";
				this.style.margin="0";
				if(this.id=='adv')
				{
					fsadv(this,1);
				}
			}
			this.onblur=function(){
				this.style.border="1px solid #7F9DB9";
				this.style.margin="1px";
				if(this.id=='adv')
				{
					fsadv(this,0);
				}
			}
			$(this).unbind('focus');
			$(this).unbind('blur');
		}
	}
	)
	$("select").each(function(i){
		this.onfocus=function(){
			this.style.background="#fffde9";
		}
		this.onblur=function(){
			this.style.background="#ffffff";
		}
	}
	)
}*/
//)

